package com.moli.iov.admin.websocket.facotry;

import com.moli.iov.admin.websocket.service.WebSocketSingleExecuteService;
import com.moli.iov.admin.websocket.utils.WebSocketContant;
import com.moli.iov.util.SpringContextUtils;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName WebSocketSingleExecuteServiceFactory
 * @Description TODO
 * @Author 李伟松
 * @CreateDate 2019-03-07 下午 5:31
 * @UpdateDate 2019-03-07 下午 5:31
 * @Version 1.0
 */
public class WebSocketSingleExecuteServiceFactory {

    final static Map<String,String> beanNameAdapterMap = new HashMap<>();

    static {
        beanNameAdapterMap.put(WebSocketContant.QUERY_PARAM,"queryParamSingleExecuteService");
        beanNameAdapterMap.put(WebSocketContant.VEHICLEMONITOR_DETAIL,"monitorDetailSingleExecuteService");
    }

    public static WebSocketSingleExecuteService getService(String beanName){

        Map<String, WebSocketSingleExecuteService> result = SpringContextUtils.getApplicationContext().getBeansOfType(WebSocketSingleExecuteService.class);

        if(StringUtils.isEmpty(beanName)){
            return null;
        }
        String adapterName = beanNameAdapterMap.get(beanName);
        beanName = StringUtils.isEmpty(adapterName)?beanName:adapterName;
        return result.get(beanName);
    }

}
